package com.zakj.scservice.service;

import com.google.gson.Gson;
import org.apache.cxf.wsdl11.SOAPBindingUtil;
import org.junit.Test;
import org.springframework.stereotype.Service;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.pipeline.ConsolePipeline;


/**
 * create by IntelliJ IDEA
 * User: HuangRZ
 * QQ: 917647409
 * Email: huangrz11@163.com
 * Date: 2017/11/24
 * Time: 13:10
 * Description:
 **/
@Service("scService")
public class SCService implements ISCService {

    @Override
    public String FindFlightMsgs(String routStartPlace, String routEndPlace, String routStartTime) {

        SiChuanAirportPageProcessor processor = new SiChuanAirportPageProcessor(routStartPlace, routEndPlace, routStartTime);
        Spider.create(processor)
                .addUrl("http://www.sichuanair.com/3uair/ibe/common/homeRedirect.do")
                .addPipeline(new ConsolePipeline())
                .thread(5)
                .run();
        return new Gson().toJson(processor.getFlightTickets());
    }

    @Test
    public void FindFlightMsgsTest() {
        String routStartPlace = "CITY_CKG_CN",  routEndPlace = "CITY_CAN_CN", routStartTime = "2018-04-10";
        SiChuanAirportPageProcessor processor = new SiChuanAirportPageProcessor(routStartPlace, routEndPlace, routStartTime);
        Spider.create(processor)
                .addUrl("http://www.sichuanair.com/3uair/ibe/common/homeRedirect.do")
                .addPipeline(new ConsolePipeline())
                .thread(5)
                .run();
        System.out.println(new Gson().toJson(processor.getFlightTickets()));
    }

}
